package com.liujun.spring4.demo.aop.application.property.editor;

import java.beans.PropertyEditorSupport;

/**
 * 自定义的属性编辑器, 使用javaBean的规范。
 *
 * <p>在运行时，将会加载对应的Editor的属性编辑器， 查找的规则是<JavaBean>Editor的规则
 *
 * @author liujun
 * @version 0.0.1
 */
public class CarEditor extends PropertyEditorSupport {

  @Override
  public void setAsText(String text) throws IllegalArgumentException {

    if (null == text && "".equals(text)) {
      throw new IllegalArgumentException("curr input text format error");
    }

    String[] input = text.split(",");
    Car car = new Car();
    car.setBrand(input[0]);
    car.setMaxSpeed(Integer.parseInt(input[1]));
    car.setPrice(Double.parseDouble(input[2]));

    setValue(car);
  }
}
